package com.neu.api.controller.admin;



import com.neu.api.dto.FlavorDTO;
import com.neu.api.properties.JWTProperties;
import com.neu.api.query.FlavorQuery;
import com.neu.api.service.FlavorService;
import com.neu.api.utils.PageResult;
import com.neu.api.utils.Result;
import com.neu.api.vo.FlavorVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "口味接口")
@RestController
@RequestMapping("admin/flavor")
@Slf4j
public class FlavorController {
    @Resource
    JWTProperties jwtProperties;

    @Resource
    FlavorService flavorService;

    @ApiOperation("添加口味")
    @PostMapping
    public Result add(FlavorDTO flavorDTO){
        flavorService.add(flavorDTO);
        return Result.ok("添加成功");
    }


    @ApiOperation("编辑口味")
    @PutMapping("/{id}")
    public Result update(@PathVariable long id,FlavorDTO flavorDTO){ //@RequestBody将前端传递的json格式的请求参数转为对象
        flavorService.update(id,flavorDTO);
        return Result.ok("修改成功");
    }


    @ApiOperation("查询口味")
    @GetMapping
    public Result<List<FlavorVO>> find(FlavorQuery flavorQuery){ //flavorQuery封装了查询的条件
        PageResult<FlavorVO> page = flavorService.find(flavorQuery);
        return Result.ok("成功",page.getList(),page.getTotal());
    }

    @ApiOperation("删除口味")
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable long id){
        flavorService.deleteById(id);
        return Result.ok("删除成功");
    }
}
